package org.dreamwork.jasmine2.engine;

import org.dreamwork.jasmine2.web.client.*;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 2010-12-9
 * Time: 23:32:15
 */
public class Browser {
    public final boolean isIE;
    public final boolean isIE6;
    public final boolean isIE7;
    public final boolean isIE8;
    public final boolean isIE9;
    public final boolean isIE10;
    public final boolean isGecko;
    public final boolean isFirefox;
    public final boolean isWebKit;
    public final boolean isChrome;
    public final boolean isSafari;
    public final boolean isOpera;
    public final boolean isPresto;

    public final String userAgent;
    public final Version version;
    public final DeviceType device;
    public final OperationSystem os;
    public final BrowserType type;
    public final RenderKernel kernel;
    public final UserAgent agent;

    public final boolean isIPhone, isIPad, isAndroid, isMobileDevice;

    Browser (String userAgent) {
        this.userAgent = userAgent;
        UserAgentParser parser = new UserAgentParser ();
        agent = parser.parse (userAgent);

        version = agent.getVersion ();
        device = agent.getDevice ();
        os = agent.getOs ();
        type = agent.getType ();
        kernel = agent.getKernel ();

        isIE6 = type == BrowserType.InternetExplorer && version.major == 6;
        isIE7 = type == BrowserType.InternetExplorer && version.major == 7;
        isIE8 = type == BrowserType.InternetExplorer && version.major == 8;
        isIE9 = type == BrowserType.InternetExplorer && version.major == 9;
        isIE10 = type == BrowserType.InternetExplorer && version.major == 10;
        isIE = isIE6 || isIE7 || isIE8 || isIE9 || isIE10;
        isChrome = type == BrowserType.Chrome;
        isFirefox = type == BrowserType.FireFox;
        isGecko = kernel.getType () == RenderkernelType.Gecko;
        isSafari = type == BrowserType.Safari;
        isWebKit = kernel.getType () == RenderkernelType.AppleWebKit;
        isOpera = type == BrowserType.Opera;
        isPresto = kernel.getType () == RenderkernelType.Presto;

        isIPad = device == DeviceType.IPAD;
        isIPhone = device == DeviceType.IPHONE;
        isAndroid = device == DeviceType.Android;
        isMobileDevice = isIPad || isIPhone || isAndroid;
    }
}